package main

import (
	"encoding/xml"
	"net"
	"time"
)

/************** udp *******************/
type UdpBufType [1400]byte
type MacType [13]byte
type KeyType MacType

type RecvUdpChanDataType struct {
	packageSize int
	buf         UdpBufType
	addr        net.UDPAddr
}

type UdpDataType struct {
	buf      UdpBufType
	dataSize int
}

type MapType struct {
	busy          bool
	mac           MacType
	udpAddr       net.UDPAddr
	tcpAddrString string
}

type MapValueType struct {
	udpAddr       net.UDPAddr
	tcpAddrString string
}

type UpDownParaKeyType struct {
	m        string
	streamId int
}

type UpDownParaValueType struct {
	sessionId     int
	video         bool
	audio         bool
	downLoadDatas [maxDownloadNum]DownLoadDataType
	videoPara     PushVideoParaType
	audioPara     PushAudioParaType

	vChan chan []byte
	aChan chan []byte
	busy  bool
}

type DownLoadDataType struct {
	busy      bool
	sessionId int
	video     bool
	audio     bool
	udpAddr   net.UDPAddr
}

type DwonLoadValueType struct {
	sessionId int
	video     bool
	audio     bool
}

type MediaHeadType struct {
	mac                 MacType
	streamId            int
	timeStamp           uint32
	frameIndex          uint32
	frameSize           uint32
	totalFragmentNumber uint16
	fragmentNumber      uint16
}

type testRecvVideoCompleteDataType struct {
	frameIndex           uint32
	recvedFragmentNumber uint16
	totalFragmentNumber  uint16
}

/************** udp *******************/

/************** tcp *******************/
type TcpClientAddrType struct {
	busy bool
	//addrString string
	conn              net.Conn
	lastHeartbeatTime int64
}

/************** tcp *******************/

/************** common *******************/
type ProtoHeadType struct {
	tag      uint16
	version  uint16
	cmd      uint16
	bodySize uint16
}

/************** common *******************/

/************** proto *******************/
type LoginoutDataType struct {
	XMLName    xml.Name `xml:"udi"`
	SessionId  int      `xml:"SessionId"`
	IdentityId string   `xml:"IdentityId"`
	UserId     int      `xml:"UserId"`
	UserName   string   `xml:"UserName"`
	UserPwd    string   `xml:"UserPwd"`
	Authority  int      `xml:"Authority"`
}

type CommonResponseDataType struct {
	XMLName   xml.Name `xml:"udi"`
	SessionId int      `xml:"SessionId"`
	State     int      `xml:"State"`
}

type RequestPushStreamDataType struct {
	XMLName    xml.Name          `xml:"udi"`
	SessionId  int               `xml:"SessionId"`
	IdentityId string            `xml:"IdentityId"`
	MediaId    string            `xml:"MediaId"`
	MediaVideo int               `xml:"MediaVideo"`
	VideoParam PushVideoParaType `xml:"VideoParams"`
	MediaAudio int               `xml:"MediaAudio"`
	AudioParm  PushAudioParaType `xml:"AudioParms"`
}

type PushVideoParaType struct {
	Width   int     `xml:"Width"`
	Height  int     `xml:"Height"`
	Bitrate float64 `xml:"Bitrate"`
	Enctype string  `xml:"Enctype"`
}

type PushAudioParaType struct {
	Channel    int     `xml:"Channel"`
	SampleRate float64 `xml:"SampleRate"`
	BitWidth   int     `xml:"BitWidth"`
	EncType    string  `xml:"EncType"`
	Bitrate    float64 `xml:"Bitrate"`
}

type CanclePushStreamDataType struct {
	XMLName    xml.Name `xml:"udi"`
	SessionId  int      `xml:"SessionId"`
	IdentityId string   `xml:"IdentityId"`
	MediaId    string   `xml:"MediaId"`
	MediaVideo int      `xml:"MediaVideo"`
	MediaAudio int      `xml:"MediaAudio"`
}

type RequestPullStreamDataType struct {
	XMLName    xml.Name `xml:"udi"`
	SessionId  int      `xml:"SessionId"`
	IdentityId string   `xml:"IdentityId"`
	MediaId    string   `xml:"MediaId"`
	Video      int      `xml:"Video"`
	Audio      int      `xml:"Audio"`
}

type ResponsePullStreamDataType struct {
	XMLName    xml.Name          `xml:"udi"`
	SessionId  int               `xml:"SessionId"`
	State      int               `xml:"State"`
	MediaVideo int               `xml:"MediaVideo"`
	VideoParam PushVideoParaType `xml:"VideoParams"`
	MediaAudio int               `xml:"MediaAudio"`
	AudioParam PushAudioParaType `xml:"AudioParms"`
}

type CanclePullStreamDataType struct {
	XMLName    xml.Name `xml:"udi"`
	SessionId  int      `xml:"SessionId"`
	IdentityId string   `xml:"IdentityId"`
	MediaId    string   `xml:"MediaId"`
	Video      int      `xml:"Video"`
	Audio      int      `xml:"Audio"`
}

/************** proto *******************/

/************** speed ctrl *******************/
type SendSpeedCtrlInfoType struct {
	byteRatePerSecond    int
	delayTimeUsPerSecond time.Duration
	sleepTimesPerSecond  time.Duration
	sleepTimeUsPerTime   time.Duration

	sleepOneTimeSendBytes uint64
	totalSendBytes        uint64
	nextSleepSendBytes    uint64
}

/************** speed ctrl *******************/
